package ru.cannabis.database.maps;

import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import ru.cannabis.game.player.Player;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: Администратор
 * Date: 10.03.13
 * Time: 15:06
 * To change this template use File | Settings | File Templates.
 */
public class PlayerMapper implements ParameterizedRowMapper<Player>
{
    private Player player;

    public PlayerMapper(Player player)
    {
        if (player != null)
        {
            this.player = player;
        }
        else
        {
            this.player = new Player();
        }
    }

    @Override
    public Player mapRow(ResultSet resultSet, int i) throws SQLException
    {
        if (player == null)
            player = new Player();

        player.setId(resultSet.getInt("account_id"));
        player.setVkId(resultSet.getString("user_vk_id"));
        player.setName(resultSet.getString("user_name"));
        player.setLastname(resultSet.getString("user_lastname"));

        return player;
    }
}
